<template>
  <div class="login">
    <div class="box">
      <div class="logo">
        <span>{{ local.systemInfo?.name }}</span>
      </div>
      <a-form ref="formRef" size="large" :rules="rules" :model="form.data" layout="vertical" @submit="login">
        <a-form-item field="username" hide-label validate-trigger="blur">
          <a-input v-model="form.data.username" :placeholder="$t('login.login.60ze746x85s0')" allow-clear>
            <template #prefix>
              <icon-user />
            </template>
          </a-input>
        </a-form-item>
        <a-form-item field="password" hide-label validate-trigger="blur">
          <a-input-password v-model="form.data.password" :placeholder="$t('login.login.60ze746x8n80')" allow-clear>
            <template #prefix>
              <icon-lock />
            </template>
          </a-input-password>
        </a-form-item>
        <!-- <a-form-item field="isRead">
          <a-checkbox v-model="form.data.isRead">{{$t('login.login.60ze746x8ww0')}}</a-checkbox>
        </a-form-item> -->
        <a-form-item>
          <a-button html-type="submit" type="primary" long>{{$t('login.login.60ze746x94c0')}}</a-button>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>

<script lang='ts' setup>
import { reactive } from 'vue';
import { apiLogin } from '@/api/login'
import { useRouter } from 'vue-router'
const local = useLocal()
const router = useRouter()
const form = reactive({
  data: {
    username: '',
    password: ''
  },
  loading: false
});

const rules = {
  username: [
    {
      required: true,
      message: t('login.login.60ze746x85s0'),
    },
  ],
  password: [
    {
      required: true,
      message: t('login.login.60ze746x8n80'),
    }
  ]
}
const login = async ({ errors }: any) => {
  if (errors) return;
  const { code, data } = await apiLogin({
    ...form.data
  })
  if (code != 200) return;
  local.token = data.accessToken
  // local.usermsg = data
  await local.getUserMsg()
  router.replace('/index')
}
</script>

<style scoped lang="less">
.login {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  padding: 5px;
  position: relative;

  .box {
    width: 400px;
    height: 400px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    // box-shadow: 0 0 7px 2px rgba(0, 0, 0, 0.08);
    box-shadow: var(--main-box-shadow);
    border-radius: 2px;
    position: relative;

    .logo {
      display: flex;
      align-items: center;
      margin-right: 10px;
      margin-bottom: 50px;

      span {
        // text-shadow:
        //   -1px 1px #bbb,
        //   -2px 2px #bbb,
        //   -3px 3px #bbb,
        //   -4px 4px #bbb,
        //   -5px 5px #bbb;
        font-size: 25px;
        font-family: "微软雅黑";
        // color: #000;
        color: var(--font-color-1);
      }

      img {
        width: 50px;
        margin-right: 10px;
      }
    }

  }

  .copyright {
    position: absolute;
    bottom: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: var(--font-size-1);
    color: var(--font-color-2);

    span+span {
      margin-left: 5px;
    }
  }
}

.arco-form-item {
  margin-bottom: 30px;
}

.arco-form {
  width: 80%;
}
</style>
